package com.neusoft.NursingHome.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.NursingHome.po.CustomerMealCalendar;
import com.neusoft.NursingHome.po.ResponseBean;
import com.neusoft.NursingHome.service.CustomerMealCalendarService;

@RestController
@RequestMapping("/customermealcalendar")
public class CustomerMealCalendarController {

    @Autowired
    private CustomerMealCalendarService customerMealCalendarService;

    /**
     * 获取客户膳食配置列表
     * @return 返回包含所有客户膳食配置列表的 ResponseBean
     */
    @GetMapping("/all")
    public ResponseBean<List<CustomerMealCalendar>> getAllCustomerMealConfigs() {
        List<CustomerMealCalendar> mealConfigs = customerMealCalendarService.getAllCustomerMealConfigs();
        return new ResponseBean<>(mealConfigs);
    }

    /**
     * 根据客户 ID 获取单个客户膳食配置
     * @param customerId 客户的唯一标识符
     * @return 返回包含该客户膳食配置列表的 ResponseBean
     */
    @GetMapping("/customer/{customerId}")
    public ResponseBean<List<CustomerMealCalendar>> getMealConfigsByCustomerId(@PathVariable Integer customerId) {
        List<CustomerMealCalendar> mealConfigs = customerMealCalendarService.getMealConfigsByCustomerId(customerId);
        return new ResponseBean<>(mealConfigs);
    }

    /**
     * 添加膳食配置
     * @param customerMealCalendar 客户膳食配置对象
     * @return 返回添加结果的 ResponseBean
     */
    @PostMapping("/add")
    public ResponseBean<Boolean> addCustomerMealConfig(@RequestBody CustomerMealCalendar customerMealCalendar) {
        boolean result = customerMealCalendarService.addCustomerMealConfig(customerMealCalendar);
        return new ResponseBean<>(result);
    }

    /**
     * 根据 ID 逻辑删除客户膳食配置
     * @param id 客户膳食配置的唯一标识符
     * @return 返回删除结果的 ResponseBean
     */
    @DeleteMapping("/delete/{id}")
    public ResponseBean<Boolean> deleteCustomerMealConfig(@PathVariable Integer id) {
        boolean result = customerMealCalendarService.deleteCustomerMealConfig(id);
        return new ResponseBean<>(result);
    }

    /**
     * 根据用餐时间查找客户膳食配置
     * @param time 用餐时间
     * @return 返回符合条件的客户膳食配置列表的 ResponseBean
     */
    @GetMapping("/time/{time}")
    public ResponseBean<List<CustomerMealCalendar>> getMealConfigsByTime(@PathVariable String time) {
        List<CustomerMealCalendar> mealConfigs = customerMealCalendarService.getMealConfigsByTime(time);
        return new ResponseBean<>(mealConfigs);
    }
}